﻿using LPBToolsLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 电子票存档工具
{
    public partial class FOnUploadRun : Form
    {
        public List<string> sRunLog = new List<string>();

        public List<string> sDeleteFileName = new List<string>();

        public Mutex sMutex = new Mutex(false, "FOnUploadRun-20240726");

        public ListBox listBoxEBillsList { get; set; } = null;

        public Thread MainRunThd { get; set; } = null;

        public FOnUploadRun()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (sRunLog.Count > 0)
            {
                sMutex.WaitOne();
                try
                {
                    foreach (string sInfo in sRunLog)
                        richTextBoxRunlog.AppendText(sInfo);
                    sRunLog.Clear();
                    RichTextGoBottom.GoBottom(richTextBoxRunlog);
                    if (listBoxEBillsList != null)
                        foreach (string sFile in sDeleteFileName)
                            listBoxEBillsList.Items.Remove(sFile);
                    sDeleteFileName.Clear();
                }
                finally
                {
                    sMutex.ReleaseMutex();
                }
            }

            if (MainRunThd==null)
            {
                labelInfo.Text = "已经完成上传工作，可以关闭本窗体！";
                buttonClose.Enabled = true;
            }
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
